package ai.people.netmon.telegram.controller;

import ai.people.netmon.framework.domain.telegram.entity.Channels;
import ai.people.netmon.framework.model.response.ResponseResult;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import ai.people.netmon.telegram.domain.request.channels.ChannelsRequest;
import ai.people.netmon.telegram.service.ManageChannelsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @description:
 * @author: Xing.Wei
 * @time: 2020-12-26 14:17
 */
@Validated
@RestController
@RequestMapping("/manage")
public class ManageChannelsController {

    @Autowired
    private ManageChannelsService channelsServiceImpl;


    /**
     * 添加群组
     *
     * @param channels 群组
     * @return {@link ResponseResult}
     */
    @PostMapping("/channel")
    public Result<?> addChannel(@Valid @RequestBody Channels channels){
        // TODO: 2022/1/7 确定必填参数 实体类增加校验注解
        channelsServiceImpl.addChannel(channels);
        return ResultUtil.success();
    }

    /**
     * 修改群组
     *
     * @param channels 群组
     * @return {@link ResponseResult}
     */
    @PutMapping("/channel")
    public Result<?> updateChannel(@RequestBody Channels channels){
        // TODO: 2022/1/7 增加校验
        channelsServiceImpl.updateChannel(channels);
        return ResultUtil.success();
    }

    /**
     * 分页查询
     *
     * @param channelsConditions 查询条件
     * @return {@link ResponseResult}
     */
    @GetMapping("/channel")
    public Result<?> queryChannelPage(@RequestBody ChannelsRequest channelsConditions){
        return ResultUtil.success(channelsServiceImpl.selectChannelsPage(channelsConditions));
    }

    /**
     * 按id查询群组
     *
     * @param id 群组id
     * @return {@link ResponseResult}
     */
    @GetMapping("/channel/{id}")
    public Result<?> queryChannel(@PathVariable Long id){
        return ResultUtil.success(channelsServiceImpl.selectById(id));
    }


    /**
     * 退群
     *
     * @param id 群组id
     * @return {@link ResponseResult}
     */
    @DeleteMapping("/channel/{id}")
    public Result<?> exitChannel(@PathVariable Long id){
        channelsServiceImpl.exitChannels(id);
        return ResultUtil.success();
    }



}
